package com.Final.hj;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class SocketAdapter extends ArrayAdapter<SocketData> {

    private int socket_id;//显示的item

    private ImageView socket_img;
    private TextView socket_uname, socket_msg, socket_time, socket_msg_num;

    public SocketAdapter(Context context, int socketId, List<SocketData> socketData){
        super(context, socketId, socketData);
        socket_id = socketId;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent){
        //获取当前滚动实例
        SocketData socketList = getItem(position);

        View view = LayoutInflater.from(getContext()).inflate(socket_id, parent, false);

        initView(view);

        socket_uname.setText(socketList.getUname());
        socket_time.setText(socketList.getMsgTime());
        socket_img.setImageResource(Integer.parseInt(socketList.gethImgId()));
        socket_msg.setText(socketList.getMsg());
        //获取未读消息数量  该get方法已经做处理 当未读数量大于99 返回的是99+
        if(socketList.getNoReadNum().equals("0")){
            //这里就不做消失
            socketList.setNoReadNum("");
            socket_msg_num.setBackgroundColor(Color.parseColor("#00000000"));//透明
        }else{
            socket_msg_num.setText(socketList.getNoReadNum());
            socket_msg_num.setBackgroundColor(Color.parseColor("#d84c29"));
        }

        //返回view
        return view;
    }


    public void initView(View v){
        socket_img = (ImageView) v.findViewById(R.id.socket_img);
        socket_uname = (TextView) v.findViewById(R.id.socket_uname);
        socket_msg = (TextView) v.findViewById(R.id.socket_msg);
        socket_time = (TextView) v.findViewById(R.id.socket_time);
        socket_msg_num = (TextView) v.findViewById(R.id.socket_msg_num);
    }
}
